package com.example.monitoringsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.monitoringsystem.bean.ExceptionPatient;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface ExceptionPatientMapper extends BaseMapper<ExceptionPatient> {
    // 获取最新的识别时间
    @Select("select max(date) from exception_patient")
    public Date getLastestDate();

    // 删除日期在指定日期之前，并且没有通知的
    @Delete("delete from exception_patient where date < ${date} and is_get = true")
    public void removeOldNotifiedException(Date date);

    // 医生获取自己病人的通知
    @Select("select * from exception_patient where patient_id in (select patient_id from patient where doctor = ${doctorId})")
    public List<ExceptionPatient> getExceptionPatientsOfDoctor(Integer doctorId);

    // 获取一个通知，根据病人id
    @Select("select * from exception_patient where patient_id = ${id}")
    public ExceptionPatient getExceptionById(Integer id);


}
